package com.hmall.api;
import com.hmall.common.utils.UserContext;
import feign.RequestInterceptor;
import feign.RequestTemplate;

/**
 * @author HW
 * @date 2025/9/4
 * @description TODO
 */
public class FeignInterceptor implements RequestInterceptor {

    @Override
    public void apply(RequestTemplate template){
        //从当前线程上获取当前用户id
        Long userId= UserContext.getUser();
        if (userId!=null){
            //如果当前线程上有,就将用户id添加给Feign请求的请求头user-info
            template.header("user-info",UserContext.getUser().toString());
        }
    }


}
